package thinking.concurrency;

import thinking.concurrency.interfacea.A;
import thinking.concurrency.packageaccess.HiddenC;

import java.lang.reflect.Method;

/**
 * Created by DELL on 2016/10/19.
 */
public class HiddenImplement {
    public static void main(String[] args) throws Exception {
        A a = HiddenC.makeA();
        a.f();
        callHiddenMethod(a, "g");
        callHiddenMethod(a, "u");
        callHiddenMethod(a, "v");
        callHiddenMethod(a, "w");
    }
    static void callHiddenMethod(Object a, String methodName) throws Exception {
        Method g = a.getClass().getDeclaredMethod(methodName);   // 可以通过反射访问到不希望被访问的内容

        g.setAccessible(true);
        g.invoke(a);
    }
}
